import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";

export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
    },
  },
  server: {
    port: 3010,
    open: true,
  },
  build: {
    outDir: "miku-ui_dist", // 指定构建结果的输出目录
    target: "es2015", // 指定要构建的目标环境，可以是某个浏览器的版本，或者是Node.js的版本
    minify: "esbuild", // 是否为代码开启压缩
    cssTarget: "chrome80",
    chunkSizeWarningLimit: 2000, // 设置大块大小（以字节为单位）的警告限制
    emptyOutDir: true, // 在构建前是否清空outDir目录
    rollupOptions: {
      external: ["vue", "element-plus"],
      output: {
        globals: {
          vue: "Vue",
          "element-plus": "ElementPlus",
        },
      },
    },
    lib: {
      // 修改入口文件路径
      entry: resolve(__dirname, "src/packages/index.ts"),
      name: "MikuUI",
      fileName: (format) => `miku-ui.${format === "es" ? "mjs" : "umd.js"}`,
    },
  },
});
